package com.cs.club.domain.service.impl;

import com.cs.club.common.entity.ErrorCode;
import com.cs.club.common.utlis.ThrowUtils;
import com.cs.club.domain.bos.ClubInfoBO;
import com.cs.club.domain.service.ClubInfoDomainService;
import com.cs.club.infra.basic.entity.ClubInfo;
import com.cs.club.infra.basic.service.ClubInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ClubInfoDomainServiceImpl implements ClubInfoDomainService {

    @Resource
    private ClubInfoService clubInfoService;

    @Override
    public Boolean addClubInfo(ClubInfoBO clubInfoBO) {
        // 参数校验
        ThrowUtils.throwIf(clubInfoBO.getClubName() == null, ErrorCode.PARAMS_ERROR,"参数为空");
        // 类型转换
        ClubInfo clubInfo = new ClubInfo();
        BeanUtils.copyProperties(clubInfoBO, clubInfo);
        // 调用infra层方法
        return clubInfoService.addClubInfo(clubInfo);
    }

    @Override
    public Boolean deleteClubInfo(ClubInfoBO clubInfoBO) {
        // 参数校验
        ThrowUtils.throwIf(clubInfoBO.getBusinessId() == null, ErrorCode.PARAMS_ERROR,"参数为空");
        // 类型转换
        ClubInfo clubInfo = new ClubInfo();
        BeanUtils.copyProperties(clubInfoBO, clubInfo);
        // 调用infra层方法
        return clubInfoService.deleteClubInfo(clubInfo);
    }

    @Override
    public Boolean updateClubInfo(ClubInfoBO clubInfoBO) {
        // 参数校验
        ThrowUtils.throwIf(clubInfoBO.getBusinessId() == null, ErrorCode.PARAMS_ERROR,"参数为空");
        // 类型转换
        ClubInfo clubInfo = new ClubInfo();
        BeanUtils.copyProperties(clubInfoBO, clubInfo);
        // 调用infra层方法
        return clubInfoService.updateClubInfo(clubInfo);
    }
}
